package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.VideoVO;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.VideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 视频
 */
@RestController
@RequestMapping("/smallVideos")
public class VideosController {
    @Autowired
    private VideosService videosService;

    /**
     * 视频-上传视频
     * POST /smallVideos
     */
    @PostMapping
    public ResponseEntity saveVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        return videosService.saveVideos(videoThumbnail, videoFile);
    }
    /**
     * 小视频-视频列表
     * GET /smallVideos
     */
    @GetMapping
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1")int page,
                                      @RequestParam(defaultValue = "10")int pagesize) {
        if (page <= 0) {
            page = 1;
        }
        PageResult<VideoVO> responseEntity = videosService.smallVideos(page, pagesize, UserHolder.getUserId());
        return ResponseEntity.ok(responseEntity);
    }

    /**
     * 小视频-关注
     * POST /smallVideos/:uid/userFocus
     */
    @PostMapping("/{followUserId}/userFocus")
    public ResponseEntity userFocus(@PathVariable("followUserId") Long followUserId) {
       return videosService.userFocus(followUserId);
    }

    /**
     * 小视频-取消关注
     * POST /smallVideos/:uid/userUnFocus
     */
    @PostMapping("/{followUserId}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("followUserId") Long followUserId) {
        return videosService.userUnFocus(followUserId);
    }

    /**
     *  小视频-点赞
     * POST /smallVideos/:id/like
     */
    @PostMapping("/{followUserId}/like")
    public ResponseEntity like(@PathVariable("followUserId") String followUserId) {
        return videosService.like(followUserId);
    }

    /**
     * 小视频-取消点赞
     * POST /smallVideos/:uid/dislike
     */
    @PostMapping("/{followUserId}/dislike")
    public ResponseEntity dislike(@PathVariable("followUserId") String followUserId) {
        return videosService.dislike(followUserId);
    }
}
